import { defineStore } from 'pinia';
import { Local } from '@/utils/storage';

interface GlobalState {
  themeType: string;
  token: string | null;
}

export const useGlobalStore = defineStore('global', {
  state(): GlobalState {
    return {
      themeType: 'sz',
      token: Local.get('token') || null, // 从本地存储中初始化 token
    };
  },
  actions: {
    setToken(token: string) {
      this.token = token;
      Local.set('token', token); // 存储 token 到本地存储
      console.log('Token set:', this.token);
    },
    clearToken() {
      this.token = null;
      Local.remove('token'); // 从本地存储中移除 token
      console.log('Token cleared');
    },
  },
});